let BaseParser = require('./BaseParser');

class CatalogItemParser extends BaseParser {
    /**
     * Creates an instance of CatalogItemParser.
     * @param {Object} $ 解析器
     * @param {NodeElement} elem DOM节点
     * @memberof CatalogItemParser
     */
    constructor() {
        super('CatalogItemParser');
    }

    parser(elem, $) {
        return this.toModal(elem, $);
    }

    /**
     * 将DOM节点解析为JSON对象
     * 
     * @returns Object
     * @memberof CatalogItemParser
     */
    toModal(elem, $) {
        let removeEnterAndSpace = this.removeEnterAndSpace;
        return {
            title: removeEnterAndSpace(elem.find('.subject-list .list-txt1').text()),
            qst_text: removeEnterAndSpace($(elem.find('.subject-list .list-txt2>a')[0]).text()),
            qst_url: removeEnterAndSpace($(elem.find('.subject-list .list-txt2>a')[0]).attr('href')),
            paper_text: removeEnterAndSpace($(elem.find('.subject-list .list-txt2>a')[1]).text()),
            paper_url: removeEnterAndSpace($(elem.find('.subject-list .list-txt2>a')[1]).attr('href'))
        }
    }
}

module.exports = CatalogItemParser;